package wj.d822;

import java.util.Scanner;

public class Hanzhi {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        // 第一行的字符串
        String str = scanner.nextLine();
        StringBuilder sb = new StringBuilder(str);
        // 第二行对应操作数量
        int optCount = scanner.nextInt();
        while (--optCount >= 0) {
            int opt = scanner.nextInt();
            if (1 == opt) {// 末尾加字母
                sb.append(scanner.nextLine().trim());
            } else if (2 == opt) {
                int pos = scanner.nextInt();
                System.out.println(findNearPos(sb.toString().toCharArray(), pos));
            }
        }
    }

    public static int findNearPos(char[] chars, int pos) {

        int left = pos - 1;
        int right = pos + 1;
        char flag = chars[pos];
        while (true) {
            boolean l = false, r = false;
            if (left >= 0) {
                if (flag == chars[left]) {
                    l = true;
                }
            }
            if (right < chars.length) {
                if (flag == chars[right]) {
                    r = true;
                }
            }
            if (l) {
                return Math.abs(pos - left);
            }
            if (r) {
                return Math.abs(pos - right);
            }
            left--;
            right++;
            if (left < 0 && right >= chars.length) {
                return -1;
            }
        }
    }
}
